package com.dianrui.fmi.activity;

import android.content.Intent;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.dianrui.fmi.R;
import com.dianrui.fmi.util.StringUtils;
import com.dianrui.fmi.util.ToastUtil;

import butterknife.BindView;
import butterknife.OnClick;

public class ForgetPasswordNextActivity extends BaseActivity {
    private String mail;


    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.edit_verifcationcode)
    EditText editVerifcationcode;


    @BindView(R.id.save_btn)
    Button saveBtn;

    @Override
    public int getContentViewId() {
        return R.layout.activity_forgetpassnext;
    }

    @Override
    public void initView() {
        if (getIntent() != null && getIntent().getExtras() != null) {
            mail=getIntent().getStringExtra("email");
        }
        title.setText(getString(R.string.forget_password));


        editVerifcationcode.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {}

            @Override
            public void afterTextChanged(Editable s) {
                if (editVerifcationcode.length()==6) {
                    saveBtn.setBackgroundResource(R.drawable.login_orange_shape);
                }else {
                    saveBtn.setBackgroundResource(R.drawable.gray_shape);
                }
            }
        });

    }


    @OnClick({R.id.back, R.id.save_btn})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.save_btn:
                if (StringUtils.isEmpty(editVerifcationcode.getText().toString())) {
                    ToastUtil.showToast("Please input your Verifcation Code");
                }else {
                    forgetPassword();
                }

                break;
                default:
                    break;
        }
    }

    private void forgetPassword() {
        startActivity(new Intent(ForgetPasswordNextActivity.this,ForgetPasswordFinalActivity.class).putExtra("email",mail).putExtra("verifyCode",editVerifcationcode.getText().toString()));

    }
}
